package com.lirisheng.experiment.autoConfig;


import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@EnableConfigurationProperties({CustomHelloProperties.class,CustomPoolTaskProperties.class})
public class AutoConfig {

    @Bean
    @ConditionalOnProperty(prefix = "lirisheng.auto",name = "enable",havingValue = "true")
    HelloConfig helloConfig(){
        return  new HelloConfig();
    }

    @Bean("customPoolTask")
    ThreadPoolTaskExecutor threadPoolTaskExecutor(CustomPoolTaskProperties customPoolTaskProperties){
        ThreadPoolTaskExecutor threadPoolTaskExecutor=new ThreadPoolTaskExecutor();
        threadPoolTaskExecutor.setCorePoolSize(customPoolTaskProperties.getCorePoolSize());
        threadPoolTaskExecutor.setMaxPoolSize(customPoolTaskProperties.getMaxPoolSize());
        System.out.println("自动配置的自定义线程池customPoolTask其作用");
        return threadPoolTaskExecutor;
    }

}
